<template>
  <div class="menuUi">
    <div v-for="item in buttons" :key="item.name" class="menu">
      <div v-if="item.children && item.children.length">
        <span class="menuTitle" v-text="item.name" />
        <div
          v-for="item_ in item.children"
          :key="item_.name"
          @click="item_.click"
          class="menuItem"
        >
          <el-icon v-if="item_.icon">
            <component :is="item_.icon" />
          </el-icon>
          <span v-text="item_.name" />
        </div>
      </div>
      <div v-else class="menuItem" @click="item.click">
        <el-icon v-if="item.icon" :color="item.color">
          <component :is="item.icon" />
        </el-icon>
        <span v-text="item.name" />
      </div>
    </div>
  </div>
</template>

<script setup>
import { shallowRef, watch } from 'vue';
import { showContext } from '../service/vueService.js';
import { edgeMenuButton } from '../service/options.js';

const props = defineProps({
  // eslint-disable-next-line vue/require-default-prop
  data: null,
});
const buttons = shallowRef([]);
watch(
  () => props.data,
  cur => {
    if (cur) {
      buttons.value = edgeMenuButton(props.data, showContext);
    }
  },
  { immediate: true },
);
</script>
<style scoped lang="scss">
.menu {
}
.menuTitle {
  font-size: 10px;
  color: #c0bfbf;
  text-align: left;
  transform: scale(0.7);
}
.menuItem {
  font-size: 11px;
  text-align: center;
  display: flex;
  align-items: center;
  padding: 5px 20px;
  transition: all 0.3s ease-in-out;
  &:hover {
    cursor: pointer;
    border-radius: 3px;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.2);
    background-color: #0073f3;
    color: #ffffff;
  }
  span {
    margin-left: 5px;
  }
}
</style>
